package com.example.sulingorder.controller;

import com.alibaba.nacos.common.utils.StringUtils;
import com.example.sulingorder.service.RedisUtilsService;
import com.xiao.sulingpublic.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 1322127758@qq.com
 * @date: 2022/3/16 17:19
 * @作用: Redis相关utils接口
 */
@RequestMapping("/redis")
@RestController
public class RedisUtilsController {
    @Autowired
    private RedisUtilsService redisUtilsService;

    /**
     * 获取表单防刷的code
     * @param username
     * @return
     */
    @GetMapping("/getcode")
    public String getCode(@RequestParam("username")String username){
        if(!StringUtils.isEmpty(username)){
            return redisUtilsService.getRedisFormCode(username);
        }
        return null;
    }

    /**
     * 获取redis中的订单数据
     * @param username :用户号
     * @param orderSn :订单号
     * @return
     */
    @GetMapping("/getorderdata")
    public R getOrderData(@RequestParam("username") String username,@RequestParam("orderSn") String orderSn){
        return redisUtilsService.getOrderData(username,orderSn);
    }


    /**
     * 获取redis中的所有订单数据
     * @param latitude: 纬度
     * @param longitude: 经度
     * @param scope: 要查询多少公里的范围
     * @return 返回订单数据集合,用户领取订单
     */
    @GetMapping("/getorderall")
    public R getOrderAll(@RequestParam("latitude")String latitude,@RequestParam("longitude")String longitude,@RequestParam("scope")String scope){

        return redisUtilsService.getOrderAll(latitude, longitude, scope);
    }
}
